
package main
import (
	"fmt"
)

type areaError struct {
	err string
	length float64
	width float64
}
func (e *areaError) Error() string {
	return e.err
}
func (e *areaError) lengthNagative() bool {
	return e.length < 0
} 
func (e *areaError) widthNagative() bool {
	return e.width < 0
}
func rectArea(length, width float64) (float64, error) {
	err := ""
	if length < 0 {
		err += "length is less than zero"
	}
	if width < 0 {
		if err == ""{
			err = "width is less than zero"
		}else {
			err += ",width is less than zero"
		}
	}
	if err != "" {
		return 0, &areaError{err, length, width}
	}
	return length * width, nil
}

func main() {
	length, width := -5.1, -9.8
	area, err := rectArea(length, width)
	if(err != nil) {
		if err, ok := err.(*areaError); ok {
			if err.lengthNagative() {
				fmt.Printf("main ==> error: length %0.2f is less than zero\n", err.length)
			}
			if err.widthNagative() {
				fmt.Printf("main ==> error: width %0.2f is less than zero\n", err.width)
			}
			return
		}
		fmt.Println(err)
		return
	}
	fmt.Println("area of rect", area)
}
